package leetcode101.double_pointer;

/**
 * @author Synhard
 * @version 1.0
 * @Class Code3
 * @Description 633. Sum of Square Numbers
 * Given a non-negative integer c, decide whether there are two integers a and b such that a2 + b2 = c.
 *
 * Example 1:
 *
 * Input: c = 5
 * Output: true
 * Explanation: 1 * 1 + 2 * 2 = 5
 *
 * Example 2:
 *
 * Input: c = 3
 * Output: false
 *
 * Example 3:
 *
 * Input: c = 4
 * Output: true
 *
 * Example 4:
 *
 * Input: c = 2
 * Output: true
 *
 * Example 5:
 *
 * Input: c = 1
 * Output: true
 *
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-03-27 14:03
 */
public class Code3 {
    public static void main(String[] args) {
        System.out.println(judgeSquareSum(1000000));
    }

    public static boolean judgeSquareSum(int c) {
        if (c == 1) {
            return true;
        }
        int left = 0, right = (int)Math.sqrt(c);;
        int res;
        while (left <= right) {
            res = left * left + right * right;
            System.out.println(res);
            if (res == c) {
                return true;
            }
            if (res < c) {
                left++;
            } else {
                right--;
            }
        }
        return false;
    }
}
